<?php defined('BASEPATH') OR exit('No direct script access allowed');?>

<!-- +++++ Contact List +++++ -->

<div class="pink">
    <div class="container">
        <div class="row">

            <!-- +++++ 操作 +++++ -->
            <div class="col-lg-12">
                <table width="100%">
                    <tr>
                        <td>
                            <a class="btn btn-danger" onclick="deal(1)">已读选中项</a>
                            <a class="btn btn-danger" onclick="deal(2)">删除选中项</a>
                        </td>
                        <td align="right">
                            <form class="search-form">
                                <input class="search-input" type="text" placeholder="请输入您要搜索的内容...">
                                <button class="search-button" type="submit"></button>
                            </form>
                        </td>
                    </tr>
                </table>
                <br><br>
            </div>

            <!-- +++++ 显示记录 +++++ -->
            <div class="col-lg-12">
                <div class="my-well">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th>id</th>
                                <th>姓名</th>
                                <th>邮箱</th>
                                <th>标题</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <?php foreach ($list as $v): ?>
                            <tr>
                                <td>
                                    <div class="checkbox">
                                        <label><input class="ckb" type="checkbox" value="<?=$v['id']?>"><?=$v['id']?></label>
                                    </div>
                                </td>
                                <td><?=$v['name']?></td>
                                <td><?=$v['email']?></td>
                                <td><?=$v['title']?></td>
                                <td>
                                    <a class="btn btn-danger"
                                       href="/admin/contact/show/<?=$v['id']?>">详情</a>&nbsp;
                                    <a class="btn btn-danger"
                                       onclick="update(<?=$v['id']?>)"
                                       <?php if($v['flag'] == 1){echo 'disabled="disabled"';}?>>已读</a>&nbsp;
                                    <a class="btn btn-danger" onclick="del(<?=$v['id']?>)">删除</a>
                                </td>
                            </tr>
                            <?php endforeach; ?>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div><!-- /row -->
    </div> <!-- /container -->
</div><!-- /white -->

<script>
    function update($ids) {
        if (confirm("确定已读？")) {
            window.location.href = '/admin/contact/update/' + $ids;
        }
    }
    function del($ids) {
        if (confirm("确定删除？")) {
            window.location.href = '/admin/contact/del/' + $ids;
        }
    }
    function deal($flag) {
        var ids = '';
        $(".ckb").each(function() {
            if ($(this).is(':checked')) {
                ids += '_' + $(this).val(); //逐个获取id
            }
        });
        ids = ids.substring(1); // 对id进行处理，去除第一个逗号
        if (ids.length == 0) {
            alert('请选择要操作的选项');
        } else {
            if($flag == 1)
                update(ids);
            else
                del(ids);
        }
    }
</script>